#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import datetime

from peewee import Model, AutoField, CharField, DateTimeField, DecimalField,\
    IntegerField, BooleanField, TextField, DateField, BigAutoField, ForeignKeyField
from utils.db_utils import *

"""
Created By TOBI
Date at 2021/5/22 11:14
Description: 软件的模型类
"""


class BaseModel(Model):

    class Meta:
        database = get_mysql_connect()


class CategoryModel(BaseModel):
    """收支分类模型"""
    id = AutoField()
    category_name = CharField(unique=True)
    parent_id = ForeignKeyField('self', backref='parent_category', null=True, field='id')
    delete_flag = BooleanField(default=False)
    remark = CharField()

    class Meta:
        table_name = 't_category'


class ChannelModel(BaseModel):
    """支付渠道模型"""
    id = AutoField()
    channel_name = CharField()
    delete_flag = BooleanField(default=False)
    remark = CharField()

    class Meta:
        table_name = 't_channel'


class PersonModel(BaseModel):
    """收支方模型"""
    id = AutoField()
    name = CharField()
    delete_flag = BooleanField(default=False)
    remark = CharField()

    class Meta:
        table_name = 't_person'


class InComeModel(BaseModel):
    """收支明细"""
    id = BigAutoField()
    title = CharField()
    amount = DecimalField()
    create_time = DateField(null=False)
    modify_time = DateTimeField()
    delete_flag = BooleanField(default=False)
    category = ForeignKeyField(CategoryModel, field='id', backref='category', null=False)
    in_person = ForeignKeyField(PersonModel, field='id', backref='in_person', null=False)
    out_person = ForeignKeyField(PersonModel, field='id', backref='out_person', null=False)
    channel = ForeignKeyField(ChannelModel, field='id', backref='channel', null=False)
    purpose = CharField()
    detail = TextField()
    remark = CharField()

    class Meta:
        table_name = 't_income'

